﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLCMS.Data.Accessor;
using ZLCMS.Business;
using System.Text;
using NHibernate.Criterion;
using NHibernate;
using System.Collections;
using ZLCMS.Data.Model;
using ZLCMS.Business.DwzFrame;
using ZLCMS.Business.Config;
using System.Data;

namespace ZLCMS.Web.Example
{
    public partial class TreeList_Depth_2 : System.Web.UI.Page
    {
        private int treeId = 1;

        protected void Page_Load(object sender, EventArgs e)
        {
            RpTypeBind();
        }

        private void RpTypeBind()
        {
            ITreeDefAccessor treeDefAcc = new AccessorFactory().GetTreeDefAccessor();
            IList treeDefList = treeDefAcc.CreateCriteria().Add(Expression.Eq("Parent", treeId)).AddOrder(Order.Asc("Id")).List();
            rp_depth_1.DataSource = treeDefList;
            rp_depth_1.DataBind();
        }

        protected void rp_depth_1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            //判断里层repeater处于外层repeater的哪个位置
            //（ AlternatingItemTemplate，FooterTemplate，HeaderTemplate，，ItemTemplate，SeparatorTemplate）

            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                //找到里层的repeater对象
                Repeater rep = e.Item.FindControl("rp_depth_2") as Repeater;

                //找到分类Repeater关联的数据项 
                TreeDef treeDef = (TreeDef)e.Item.DataItem;

                //获取填充子类的id 
                int parentId = treeDef.Id; 

                ITreeDefAccessor treeDefAcc = new AccessorFactory().GetTreeDefAccessor();
                IList treeDefList = treeDefAcc.CreateCriteria().Add(Expression.Eq("Parent", parentId)).AddOrder(Order.Asc("Id")).List();
                rep.DataSource = treeDefList;
                rep.DataBind();
            }
        }

    }
}
